package com.wanjia.estate.utils;

import cn.hutool.core.util.StrUtil;
import com.wanjia.estate.exception.ControllerException;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.Date;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ThreadUtil {

    private static ThreadLocal<String> slbh = new ThreadLocal<>();
    private static ThreadLocal<Date> now = new ThreadLocal<>();

    public static String getSlbh() {
        if (StrUtil.isEmpty(slbh.get())) {
            throw new ControllerException("受理编号缺失");
        }

        return slbh.get();
    }

    public static void setSlbh(String slbh) {
        ThreadUtil.slbh.set(slbh);
    }

    public static Date getNow() {
        return now.get();
    }

    public static void setNow(Date now) {
        ThreadUtil.now.set(now);
    }

    public static void removeAll() {
        slbh.remove();
        now.remove();
    }
}
